import { request, getImage} from "@/api/request";

// 即将结束
export function getBiddingFinishing(params) {
  return request(
    {
      url: "/web/bidding/finishing",
      method: "get",
      params,
    },
    false
  );
}


// 竞价域名详情
export function getBiddingInfoById(biddingId) {
  return request(
    {
      url: "/web/bidding/info/" + biddingId,
      method: "get",
    },
    true
  );
}

//出价记录
export function getBiddingRecords(params) {
  return request(
    {
      url: "/web/bidding/records",
      params,
      method: "get",
    },
    true
  );
}

//刷新token
export function refreshToken(data) {
  return request(
    {
      url: "/web/refreshToken",
      data,
      method: "post",
    },
    true,
    "noProcssing",
    true
  );
}

// 出价
export function postBidding(data) {
  return request(
    {
      url: "/web/bidding/bid",
      data,
      method: "post",
    },
    true
  );
}

//================域名push===========

// 域名push获取数据
export function getPushPageList(params) {
  return request(
    {
      url: "/web/domain/push/pageList",
      params,
      method: "get",
    },
    true
  );
}

// 域名push
export function postPushSave(data) {
  return request(
    {
      url: "/web/domain/push/save",
      data,
      method: "post",
    },
    true
  );
}

// 检查用户是否存在
export function checkUserExist(params) {
  return request(
    {
      url: "/web/user/checkUserExist",
      params,
      method: "get",
    },
    true
  );
}

// push操作
export function postPushEdit(data) {
  return request(
    {
      url: "/web/domain/push/submit",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// push操作
export function postPushEditV2(data) {
    return request(
        {
            url: "/web/domain/push/submitV2",
            data,
            method: "post",
        },
        true,
        "MessageBox"
    );
}

// 我的域名
export function domainPageList(data) {
  return request(
    {
      url: "/web/domain/pageListV2",
        data,
      method: "post",
    },
    true
  );
}

// 域名解析
export function domainResolutionList(params) {
  return request(
    {
      url: "/web/domain/resolution/pageList",
      params,
      method: "get",
    },
    true
  );
}
// 自动续费
export function setPrivacy(data) {
  return request(
    {
      url: "/web/domain/setPrivacy",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}
// 自动续费
export function autoRenew(data) {
  return request(
    {
      url: "/web/domain/autoRenew",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 获取线路
export function domainResolutionGetLine(params) {
  return request(
    {
      url: "/web/domain/resolution/getLine",
      params,
      method: "get",
    },
    true
  );
}

// 解析-保存记录
export function postResolutionSave(data) {
  return request(
    {
      url: "/web/domain/resolution/save",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 解析-修改记录
export function postResolutionModify(data) {
  return request(
    {
      url: "/web/domain/resolution/record/modify",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 解析-启用记录
export function postResolutionStart(data) {
  return request(
    {
      url: `/web/domain/resolution/record/start/${data}`,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 解析-暂停记录
export function postResolutionPause(data) {
  return request(
    {
      url: `/web/domain/resolution/record/pause/${data}`,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 解析-删除记录
export function postResolutionRemove(data) {
  return request(
    {
      url: "/web/domain/resolution/record/remove",
      data,
      method: "delete",
    },
    true,
    "MessageBox"
  );
}

// 解析日志
export function domainResolutionLogPageList(params) {
  return request(
    {
      url: "/web/domain/resolution/logPageList",
      params,
      method: "get",
    },
    true
  );
}

// 竞价域名详情
export function getDomainInfoById(params) {
  return request(
    {
      url: "/web/domain/domainInfoV2",
      params,
      method: "get",
    },
    true
  );
}


// 竞价域名详情
export function getDomainLogs(data) {
    return request(
        {
            url: "/web/domain/logV2",
            data,
            method: "post",
        },
        true
    );
}

// 竞价域名详情
export function getDownloadDomainPicById(params) {
  return getImage(
    {
      url: "/web/domain/downloadDomainPic",
      params,
      method: "get",
      responseType: "arraybuffer",
    },
    true
  ).then((res) => {
    try {
      let enc = new TextDecoder("utf-8");
      res = JSON.parse(enc.decode(new Uint8Array(res.data))); //转化成json对象
      return res;
    } catch (error) {
      return {
        code: 200,
        data:
          "data:image/png;base64," +
          btoa(
            new Uint8Array(res.data).reduce(
              (data, byte) => data + String.fromCharCode(byte),
              ""
            )
          ),
        message: "",
      };
    }
  });
}

// 我的域名
export function domainExport(data) {
  return getImage(
    {
      url: "/web/domain/exportV2",
        data,
      method: "post",
      responseType: "blob",
    },
    true
  ).then((res) => {
    try {
      const blob = new Blob([res.data], {
        type: "application/vnd.ms-excel;charset=utf-8'",
      });
      return {
        code: 200,
        data: blob,
        message: "",
      };
    } catch (error) {
      return {
        code: 500,
        data: null,
        message: "",
      };
    }
  });
}

// 资金明细导出
export function userExportData(data) {
  return getImage(
    {
      url: "/web/user/exportData",
        data,
      method: "POST",
      responseType: "blob",
    },
    true
  ).then((res) => {
    try {
      const blob = new Blob([res.data], {
        type: "application/vnd.ms-excel;charset=utf-8'",
      });
      return {
        code: 200,
        data: blob,
        message: "",
      };
    } catch (error) {
      return {
        code: 500,
        data: null,
        message: "",
      };
    }
  });
}
//批量解析
export function setRemark(data) {
    return request(
        {
            url: "/web/domain/setRemark",
            data,
            method: "post",
        },
        true,
        "MessageBox"
    );
}

//批量解析
export function batchAsalysis(data) {
  return request(
    {
      url: "/web/domain/resolution/batchSave",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 高级批量解析
export function seniorAnalysis(data) {
  return request(
    {
      url: "/web/domain/resolution/seniorSave",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 释放域名
export function preDeleteSave(data) {
  return request(
    {
      url: "/web/preDelete/save",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 释放记录
export function preDeleteList(data) {
  return request(
    {
      url: "/web/preDelete/pageList",
      data,
      method: "post",
    },
    true,
    "MessageBox"
  );
}

// 查询中介出售
export function getSellList(params) {
  return request(
    {
      url: "/web/domain/broker/sell",
      method: "get",
      params,
    },
    true
  );
}

 // 查询中介购买
 export function getEntrustList(data) {
  return request(
    {
      url: "/web/domain/broker/entrust",
      method: "post",
        data,
    },
    true
  );
}

// 查询中介购买
export function entrustSubmit(data) {
    return request(
        {
            url: "/web/domain/broker/whoisEntrust",
            method: "post",
            data,
        },
        true
    );
}

// 竞价返利
export function getBiddingRebateList(data) {
    return request(
        {
            url: "/web/biddingRebate/pageList",
            data,
            method: "post",
        },
        true
    );
}
export function getBiddingRebateStatistics() {
    return request(
        {
            url: "/web/biddingRebate/statistics",
            method: "post",
        },
        true
    );
}
